package com.szqhyxj.youxiangju.biz.creditCardEvaluation.evaluationRecord;

import android.util.Log;

import com.szqhyxj.youxiangju.sys.BaseResult;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.functions.Consumer;
import io.reactivex.schedulers.Schedulers;

/**
 * Created by leung on 2018/11/10.
 */

public class EvaluationRecordPresernter implements EvaluationRecordContract.Presenter {
    EvaluationRecordContract.View view;

    public EvaluationRecordPresernter(EvaluationRecordContract.View view) {
        this.view = view;
    }

    @Override
    public void onDestroy() {

    }

    @Override
    public void init(int pageNumber) {
        view.showLoading();
        EvaluationRecordModel.getEvaluationRecordList(pageNumber, 50)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Consumer<BaseResult<EvaluationRecordModel.EvaluationRecordListEntity>>() {
                    @Override
                    public void accept(BaseResult<EvaluationRecordModel.EvaluationRecordListEntity> evaluationRecordListEntityBaseResult) throws Exception {
                        view.dismissLoading();
                        if (evaluationRecordListEntityBaseResult.businessLogicSuccess()) {
                            List<RowsItem> list = new ArrayList<>();
                            list = evaluationRecordListEntityBaseResult.getData().getRows();
                            Log.e("====", list.size() + "");
                            view.showList(list);
                        } else {
                            view.showToast(evaluationRecordListEntityBaseResult.getMessage());
                        }
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        view.dismissLoading();
                   //     view.showToast(throwable.getMessage());

                    }
                });
    }
}
